package com.chuhe.lottery.exception;

import lombok.AllArgsConstructor;

import java.util.concurrent.ThreadFactory;

/**
 * @Author: 楚河
 * @Date: 2025年04月19日17:30
 */
@AllArgsConstructor
public class MyThreadFactory implements ThreadFactory{
    private static final MyUncaughtExceptionHandler MY_UNCAUGHT_EXCEPTION_HANDLER = new MyUncaughtExceptionHandler();
    private ThreadFactory original;  // 原始线程工厂对象

    @Override
    public Thread newThread(Runnable r) {
        // 1. 使用原始线程工厂创建线程（保留原有逻辑）
        Thread thread = original.newThread(r);
        // 2. 添加自定义逻辑：设置未捕获异常处理器
        thread.setUncaughtExceptionHandler(MY_UNCAUGHT_EXCEPTION_HANDLER);
        return thread;
    }
}
